import http from '../util/request.js';
import config from '../../config.js';
var app = getApp();
//引入这个插件，使html内容自动转换成wxml内容
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    userInfo:[],
    imgUrls: [],
    article: [],
    showModal: true,
    page: 0,
    size: 10,
    desc:'',
    tel:'',
    num:12,
      indicatorDots: false,
      autoplay: false,
      interval: 3000,
      duration: 800,
	  products:[]
  },
  load() {
    var info = wx.getStorageSync('userInfo');
    console.log(info);
    if (info.wxInfo) {
      this.setData({ 
        showModal: false
      });
    }
    //广告列表
    http.get('api', { r:'home.Adlist'}).then(data => {
      this.setData({ imgUrls: data });
    });
    //获取文章
    http.get('api', { r: 'home.Articlelist', page: this.data.page }).then(data => {
      this.setData({ article: data });
      console.log(data);
    });
    //产品列表
    http.get('api', { r: 'home.Productlist', page: this.data.page}).then(data => {
      this.setData({ products: data });
    });
  },

 

  //获取用户信息新接口
  agreeGetUser: function (e) {
    var that=this
    var app = getApp()
    app.util.getUserInfo(function (userInfo) {
      //这回userInfo为用户信息
    console.log(userInfo)
    that.setData({ 
      userInfo: userInfo.wxInfo,
      showModal: false
       });
    });
  },
  /**
   * 弹窗
   */
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },

  onLoad: function() {
      this.load();
  },
  navigator:function(e){
    wx.switchTab({
      url: e.currentTarget.dataset.url,
    })
  },
  //动画
  startNotice: function() {
    var me = this;
    var notices = me.data.notices || [];
    if( notices.length == 0 ) {
      return;
    }

    var animation = me.animation;
    //animation.translateY( -12 ).opacity( 0 ).step();
    animation.translateY( 0 ).opacity( 1 ).step( { duration: 0 });
    me.setData( { animationNotice: animation.export() });

    var noticeIdx = me.data.noticeIdx + 1;
    if( noticeIdx == notices.length ) {
      noticeIdx = 0;
    }

    // 更换数据
    setTimeout( function() {
      me.setData( {
        noticeIdx: noticeIdx
      });
    }, 400 );

    // 启动下一次动画
    setTimeout( function() {
      me.startNotice();
    }, 5000 );
  },
  onShow: function() {
    this.startNotice();

  }
})